package com.xz.knowledgeDuplication.pattern.expression;

/**
 * 加(非终结符表达式)
 *
 * @author 召
 * @date 2022-04-04 22:18:08
 */
public class Plus extends AbstractExpression {

    /**
     * 左子式
     */
    private AbstractExpression left;

    /**
     * 右子式
     */
    private AbstractExpression right;

    public Plus(AbstractExpression left, AbstractExpression right) {
        this.left = left;
        this.right = right;
    }

    @Override
    public int interpret(ExpressionContext context) {
        return left.interpret(context) + right.interpret(context);
    }

    @Override
    public String toString() {
        return "(" + left.toString() + " + " + right.toString() + ")";
    }
}
